<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  
</body>
<script>

  const obj = proxy({name:"admin",age:18,sex:"男"})
  console.log(obj);

  // 使用Object.defineProperty根据指定对象的属性，动态添加具有访问器和控制器的属性
  
  function proxy(abc){
    const obj = {};
    for(let i in abc){
      Object.defineProperty(obj, i, {
        get(){
          console.log(`有人访问了obj的${i}`)
          return abc[i]
        },
        set(val){
          console.log(`有人修改了obj的${i}，值为${val}`)
          abc[i] = val;
        }
      })
    }
    return obj;
  }

</script>
</html>